const OSS = require('ali-oss');

const client = new OSS({
    region: "oss-cn-beijing",
    bucket: "devin0831",
    accessKeyId: "LTAI5tF5SC1ZSCHLYiCa6NQh",
    accessKeySecret: "yVRUyZBOy8sXSmmw4rd0j08ZxOOEVN",
});
        

const Controller = require('egg').Controller;

class HomeController extends Controller {
  // 图片上传
  async OSS() {
    let {
        ctx
    } = this;
    const file = ctx.request.files[0];
    try {

        let result = await client.put(`${Math.random() * 100}_imgs`, file.filepath);
        this.ctx.body = {
            code: 200,
            msg: '上传成功',
            data: result
        }
    } catch (err) {
        this.ctx.body = {
            code: 404,
            msg: '上传失败',
        }
    }
}
  
}

module.exports = HomeController;